package action;

import org.apache.shiro.SecurityUtils;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

import pageModel.Menu;
import service.MenuServiceI;
import util.ShiroUtil;

import com.opensymphony.xwork2.ModelDriven;

@Action(value="menuAction")
public class MenuAction extends BaseAction implements ModelDriven<Menu>{
    private Menu menu=new Menu();
    private MenuServiceI menuService;
	public MenuServiceI getMenuService() {
		return menuService;
	}
	@Autowired
	public void setMenuService(MenuServiceI menuService) {
		this.menuService = menuService;
	}
	@Override
	public Menu getModel() {
		return menu;
	}
public void getTree(){
	if(SecurityUtils.getSubject().isAuthenticated()){
	super.writeJson(menuService.getTree(ShiroUtil.getCurrentUser().getTrole().getId()));
	}
}
public void getAllTree(){
	if(SecurityUtils.getSubject().isAuthenticated()){
	super.writeJson(menuService.getAllTree(ShiroUtil.getCurrentUser().getTrole().getId()));
	}
}
public void getResourceTree(){
	super.writeJson(menuService.getAllTree(menu.getId()));
}
}
